package com.ymatou.iapi.godmch.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.collect.Lists;
import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymatou.iapi.godmch.parameter.getDepotByIdListBean;
import com.ymatou.iapi.godmch.service.createDepotCall;
import com.ymatou.iapi.godmch.service.getDepotByIdListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.model.godmch.mch_depot_info;
import com.ymttest.database.model.godmch.mch_depot_infoExample;
import com.ymttest.database.sqlwapper.godmch.mch_depot_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.utils.TestDataManager;
/**
*批量查询仓库信息
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getDepotByIdList{
	private static getDepotByIdListBean bean;
	private static getDepotByIdListCall call;
	
	createDepotBean cbean=new createDepotBean ();
	createDepotCall ccall=new createDepotCall();
    	
	mch_depot_infoWapper depotWapper;
	mch_depot_infoExample example;
	
	private static mch_infoWapper mchInfoWapper=new mch_infoWapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量查询仓库信息");
	}

	@Before
	public void caseUp() {
		bean=new getDepotByIdListBean();
		call=new getDepotByIdListCall();
		
		depotWapper=new mch_depot_infoWapper();
		example=new mch_depot_infoExample();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void check_verify() throws InterruptedException {
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		
		example.clear();
		example.createCriteria().andDepotIdIn(bean.getDepotIdList());
        List<mch_depot_info> lst=depotWapper.selectByExample(example);
        List<mch_depot_info> return_depots=call.getDepots();
        int count=0;
        for(mch_depot_info DB_depot:lst)
        {
        	Logger.verifyEquals(return_depots.get(count).getMchId(), DB_depot.getMchId(), "验证第"+(count+1)+"个数据库字段MchId与返回的是否一致");
        	Logger.verifyEquals(return_depots.get(count).getDepotId(), DB_depot.getDepotId(), "验证第"+(count+1)+"个数据库字段DepotId与返回的是否一致");
        	Logger.verifyEquals(return_depots.get(count).getDepotTitle(), DB_depot.getDepotTitle(), "验证第"+(count+1)+"个数据库字段DepotTitle与返回的是否一致");
        	
        	//新增 20200619
        	Logger.verifyEquals(return_depots.get(count).getBuyerTitle(), DB_depot.getBuyerTitle(), "验证第"+count+"个数据库字段BuyerTitle与传入的是否一致");
        	Logger.verifyEquals(return_depots.get(count).getPicUrl(), DB_depot.getPicUrl(), "验证第"+count+"个数据库字段PicUrl与传入的是否一致");
        	
        	//查询mchInfo
        	mch_info mch_info=mchInfoWapper.selectbyMchIds(Lists.newArrayList(DB_depot.getMchId())).get(0);
        	Logger.verifyEquals(return_depots.get(count).getMchTitle(), mch_info.getMchTitle(), "验证第"+(count+1)+"个数据库字段mchTitle与返回的是否一致");
        	
        	count++;
        }
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotByIdList_001() {
		Logger.start(true,"批量查询仓库信息--验证同一商户,仓库id列表1条");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId);
			mch_depot_info  info=depotWapper.selectByExample(example).get(0);
			
			bean.setDepotIdList(Lists.newArrayList(info.getDepotId()));
			call.setData(bean);
			call.callService();			
			
			check_verify();
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotByIdList_002() {
		Logger.start(true,"批量查询仓库信息--验证同一商户,仓库id列表2条");
		try {
			
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);
			GodmchManageCallService.createDepot(mchId);
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId);
			List<mch_depot_info>  infos=depotWapper.selectByExample(example);
			
			bean.setDepotIdList(Lists.newArrayList(infos.get(0).getDepotId(),infos.get(1).getDepotId()));
			call.setData(bean);
			call.callService();			
			
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotByIdList_003() {
		Logger.start(true,"批量查询仓库信息--验证同一商户一共2条仓库,仓库id列表1条");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);
			GodmchManageCallService.createDepot(mchId);
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId);
			List<mch_depot_info>  infos=depotWapper.selectByExample(example);
			
			bean.setDepotIdList(Lists.newArrayList(infos.get(0).getDepotId()));
			call.setData(bean);
			call.callService();			
			
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotByIdList_004() {
		Logger.start(true,"批量查询仓库信息--验证同一商户,仓库id列表2条,其中1条不存在");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId);
			GodmchManageCallService.createDepot(mchId);
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId);
			List<mch_depot_info>  infos=depotWapper.selectByExample(example);
			
			bean.setDepotIdList(Lists.newArrayList(infos.get(0).getDepotId(),1111));
			call.setData(bean);
			call.callService();			
			
			check_verify();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotByIdList_005() {
		Logger.start(true,"批量查询仓库信息--验证仓库id列表2条,分别不同的商户");
		try {
			Integer mchId1 = GodmchManageCallService.CreateSellerMch();
			Integer mchId2 = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId1);
			GodmchManageCallService.createDepot(mchId2);
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdIn(Lists.newArrayList(mchId1,mchId2));
			List<mch_depot_info>  infos=depotWapper.selectByExample(example);
			
			bean.setDepotIdList(Lists.newArrayList(infos.get(0).getDepotId(),infos.get(1).getDepotId()));
			call.setData(bean);
			call.callService();			
			
			check_verify();		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotByIdList_006() {
		Logger.start(true,"批量查询仓库信息--验证两个商户分别2条仓库,仓库id列表2条,分别不同的商户");
		try {
			Integer mchId1 = GodmchManageCallService.CreateSellerMch();
			Integer mchId2 = GodmchManageCallService.CreateSellerMch();
			GodmchManageCallService.createDepot(mchId1);
			GodmchManageCallService.createDepot(mchId1);
			GodmchManageCallService.createDepot(mchId2);
			GodmchManageCallService.createDepot(mchId2);
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId1);
			List<mch_depot_info>  infos1=depotWapper.selectByExample(example);
			
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId2);
			List<mch_depot_info>  infos2=depotWapper.selectByExample(example);
			
			bean.setDepotIdList(Lists.newArrayList(infos1.get(0).getDepotId(),infos2.get(0).getDepotId()));
			call.setData(bean);
			call.callService();			
			
			check_verify();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotByIdList_007() {
		Logger.start(true,"批量查询仓库信息--验证仓库id列表为空");
		try {
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getDepotByIdList_008() {
		Logger.start(true,"批量查询仓库信息--验证修改商户名称，然后再建仓库");
		try {
			Integer mchId = GodmchManageCallService.CreateSellerMch();
			
			GodmchManageCallService.editMchInfo(mchId, "修改title_"+TestDataManager.getRandomIntNum(5), "http://pic1.ymatou.com/G01/M00/3F/CD/rBBlD1yTdyCAe7ruAABImnwn1Sc744_1_1_o1.png", "wwtest");
			GodmchManageCallService.createDepot(mchId);
			//查询DepotId
			example.clear();
			example.createCriteria().andMchIdEqualTo(mchId);
			mch_depot_info  info=depotWapper.selectByExample(example).get(0);
			
			bean.setDepotIdList(Lists.newArrayList(info.getDepotId()));
			call.setData(bean);
			call.callService();			
			
			check_verify();
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}